﻿using AntMovement.Core.IParameter;
using AntMovement.Core.Manager;
using AntMovement.Parameter;
using Prism.Commands;
using Prism.Ioc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AntMovement.ViewModels
{
    public class StatusBarViewModel : Prism.Mvvm.BindableBase
    {
        private string _versionNumber;

        public string VersionNumber
        {
            get { return _versionNumber; }
            set { SetProperty(ref _versionNumber, value); }
        }
        public TemporaryParameter Temporary { get; set; }
        private IContainerProvider _containerProvider;
        public StatusBarViewModel(ITemporaryParameter temporary, IContainerProvider containerProvider)
        {
            Temporary = (TemporaryParameter)temporary;
            _containerProvider = containerProvider;
            SetVersion();
        }

        private void SetVersion()
        {
            System.Reflection.AssemblyFileVersionAttribute[] obj = (System.Reflection.AssemblyFileVersionAttribute[])System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(System.Reflection.AssemblyFileVersionAttribute), false);
            VersionNumber = $"[版本 v {obj[0].Version} NET 5]";
        }

        public DelegateCommand Run => new DelegateCommand(() =>
        {

        });

        public DelegateCommand Connect => new DelegateCommand(async () =>
        {
            var taskManager = _containerProvider.Resolve<ITaskManager>();
            if (!Temporary.GetConnect())
            {
                await taskManager.LoopTask();
            }
            else
            {
                taskManager.StopTask();
            }
        });
    }
}
